package com.czk.bug;

import java.util.concurrent.LinkedBlockingQueue;

/**
 *
 * why技术 jdk LinkedBlockingQueue bug
 *
 * @Author:ChenZhangKun
 * @Date: 2023/1/30 21:08
 */
public class LinkedBlockingQueueBug {
    public static void main(String[] args) throws InterruptedException {
        LinkedBlockingQueue<Object> queue = new LinkedBlockingQueue<>();
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                while (true) {
                    queue.offer(new Object());
                    queue.remove();
                }
            }).start();
        }


        while (true) {
            System.out.println("begin scan, i still alive");
            queue.stream().filter(o -> o == null)
                    .findFirst()
                    .isPresent();
            Thread.sleep(100);
            System.out.println("finish scan, i still alive");
        }
    }
}
